opendir(DH,"/Users/yaping/Documents/workspace/result/ASM/") or die;
my @normal_SNP;
my @tumor_SNP;
my $normal_SNP_title="track name=\"normal SNP\" description=\"normal SNP\" useScore=0 itemRgb=On visibility=4";
my $tumor_SNP_title="track name=\"tumor SNP\" description=\"tumor SNP\" useScore=0 itemRgb=On visibility=4";
push(@normal_SNP,"$normal_SNP_title\n");
push(@tumor_SNP,"$tumor_SNP_title\n");
foreach my $file(readdir(DH)){
	if($file=~/methylCGsRich_ASM_(\w+)Merge_(\w+)_SNP_all_afterBaseQfilter.txt/){
		my $sample=$1;
		my $chr=$2;
		open(FH,"</Users/yaping/Documents/workspace/result/ASM/$file");
		my @in=<FH>;
		chomp(@in);
		close(FH);
		push(@snp_out,"$snp_title\n");
		foreach my $line(@in){
			my @splitin = split "\t",$line;
			my $position=abs($splitin[0]);
			if($sample eq "normal"){
				push(@normal_SNP,"$chr\t$position\t$position\t$sample-snp\n");
			}
			else{
				push(@tumor_SNP,"$chr\t$position\t$position\t$sample-snp\n");
			}
		}
	}
}

open(OUT,">/Users/yaping/Documents/workspace/result/ASM/methylCGsRich_ASM_AllSnp_tumorMerge_SNP.bed");
print OUT @tumor_SNP;
close(OUT);
open(OUT,">/Users/yaping/Documents/workspace/result/ASM/methylCGsRich_ASM_AllSnp_normalMerge_SNP.bed");
print OUT @normal_SNP;
close(OUT);
